/**
  * Author: Mei
  * Date: 2021-01-13 10:21
  * Description: chrono库
  * chrono库主要包含三种类型：时间间隔duration、时钟clocks和时间点time point
  *
  */
#include <iostream>
#include <chrono>
#include <ctime>
#include <iomanip>

using namespace std::chrono;

int main() {
    //1、表示时间点的time point
    //time_point表示一个时间点，用来获取从它的clock的纪元开始所经过的duration和当前时间
    typedef duration<int, std::ratio<60 * 60 * 24>> days_type;
    time_point<system_clock, seconds> today = time_point_cast<seconds>(system_clock::now());

    std::cout << today.time_since_epoch().count() << " days since epoch" << std::endl;

    system_clock::time_point now = system_clock::now();
    std::cout << "now is: "<<now.time_since_epoch().count() << std::endl;
    std::time_t last = system_clock::to_time_t(now - hours(24));
    std::time_t next = system_clock::to_time_t(now + hours(24));
    std::cout << "One day ago, the time was " << std::put_time(std::localtime(&last), "%Y-%m-%d %H:%M:%S") << '\n';
    std::cout << "Next day, the time was " << std::put_time(std::localtime(&next), "%Y-%m-%d %H:%M:%S") << '\n';

    return 0;
}